/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DataPublic.java
 *
 * Created on 5 janv. 2010, 04:40:49
 */
package Interface;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import moteur.Transport;
import moteur.paquet.PaquetVideException;
import moteur.paquet.PionsEnMain;
import moteur.partie.Joeur;
import moteur.partie.Jouer;
import moteur.partie.Partie;

/**
 *
 * @author Administrateur
 */
public class DataPublic extends javax.swing.JPanel {

    /** Creates new form DataPublic */
    public DataPublic() {
        initComponents();
        setOpaque(false);
        setPreferredSize(new Dimension(140, 600));
    }

    @Override
    public void paint(Graphics g) {

        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        Partie p = Partie.getInstance();
        Vector<Jouer> v = p.getJoeurs();
        Jouer courant = p.getJoeurCourant();
        Transport[] t = Transport.values();
        byte[] b;
        int h = this.getHeight() / 7;
        int y = 12;
        int x = 0;

        for (Jouer j : v) {

            Joeur J = (Joeur) j;
            b = J.getPions().getPaquet();

            if (courant == j) {
                g2.setColor(Color.darkGray);
                g2.drawRect(x + 1, y - 11, this.getWidth() - 5, h - 1);
            } else {
                g2.setColor(Color.black);
            }

            g2.drawString(J.getNom(), x, y);
            for (int i = b.length; --i >= 0;) {
                for (int k = b[i]; --k >= 0;) {
                    g2.drawImage(t[i].getImage(), x, y, null);
                    x += 20;
                }
            }
                
                int l = 0;
                try {
                    l = J.getPions().totalCaché();
                } catch (PaquetVideException ex) {
                    Logger.getLogger(DataPublic.class.getName()).log(Level.SEVERE, null, ex);
                }
                for (int k = l; --k >= 0;) {
                    g2.drawImage(Transport.getImageDefaut(), x, y, null);
                    x += 20;
                }
            
            x = 0;
            y += h;
        }
        }

    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setPreferredSize(new java.awt.Dimension(64, 256));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 64, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 256, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
